package com.mycjj.android.activity;

import com.mycjj.android.ProjectDataManage;
import com.mycjj.android.R;
import com.mycjj.android.bean.LoginMemberBean;
import com.mycjj.android.bean.MemberBean;
import com.mycjj.android.bean.MemberBean.Member;
import com.mycjj.android.fragment.GoldRecordAFragment;
import com.mycjj.android.fragment.GoldRecordBFragment;
import com.mycjj.android.fragment.MainActivityFragment;
import com.mycjj.android.fragment.MainArticlesFragment;
import com.mycjj.android.fragment.MainNewCarFragment;
import com.mycjj.android.fragment.MainServiceFragment;
import com.mycjj.android.widget.TabPageIndicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

//元宝记录
public class Score_GoldRecordActivity extends BaseActivity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_score_gold_record);
		initHeader();
		init();
		initData();
	}
	
	private ImageView mHeaderLeftImageview;
	private Button mHeaderRightButton;
	private TextView mHeaderTitleTextView;

	private void initHeader() {
		mHeaderLeftImageview = (ImageView) findViewById(R.id.header_left_button);
		mHeaderLeftImageview.setImageResource(R.drawable.back);
		mHeaderRightButton = (Button) findViewById(R.id.header_right_button);
		mHeaderRightButton.setVisibility(View.GONE);
		mHeaderTitleTextView = (TextView) findViewById(R.id.header_title_textview);
		mHeaderTitleTextView.setText("元宝记录");
		mHeaderLeftImageview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Score_GoldRecordActivity.this.finish();
			}
		});
	}
	private ViewPager pager;
	private TabPageIndicator indicator;
	private TextView tv_name;
	private void init(){
		tv_name = (TextView)findViewById(R.id.tv_name);
		pager = (ViewPager) findViewById(R.id.pager);
		indicator = (TabPageIndicator) findViewById(R.id.indicator);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		int use_gold = dataManager.getTotalPoints() - dataManager.getPoints();
		tv_name.setText("我共有"+String.valueOf(dataManager.getPoints())+"元宝，消耗"+use_gold+"元宝");
	}

	
	private void initData() {
		FragmentPagerAdapter adapter = new MainPageAdapter(getSupportFragmentManager());
		pager.setAdapter(adapter);
		indicator.setViewPager(pager);
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	private static final String[] CONTENT = new String[] { "获取纪录", "消费纪录" };
	
	private Fragment [] FRAGMENT_ARRAY = {GoldRecordAFragment.newInstance(),GoldRecordBFragment.newInstance()};

	class MainPageAdapter extends FragmentPagerAdapter {
		public MainPageAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			return FRAGMENT_ARRAY[position];
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return CONTENT[position % CONTENT.length].toUpperCase();
		}

		@Override
		public int getCount() {
			return CONTENT.length;
		}
	}

	
}
